package com.itheima.userservice.controller;

import com.itheima.userservice.service.ReadPDFService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ThreadPoolExecutor;

@RestController
@RequestMapping("/readPDF")
@Api("读取pdf")
public class ReadPDFController {

    private ReadPDFService readPDFService;

    @Autowired
    private ReadPDFService ReadPDFController(ReadPDFService readPDFService) {
        return this.readPDFService = readPDFService;
    }

    //读取pdf文件,在前端展示
    @GetMapping("/read")
    public void ReadPDF(int pageNo, int pageSize, HttpServletResponse response) {
        Integer pdfSize = 0;
        try {
            pdfSize = readPDFService.read(pageNo, pageSize, response);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //将pdf总页数放在head中返回
        response.addHeader("pdf-size", pdfSize.toString());
    }

}
